package com.example.learnvitamio.live

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.learnvitamio.R

/**
 *
 * @Author： LJH
 * @Time： 2022/7/14
 * @description：
 */
class LiveAdapter(context: Context):RecyclerView.Adapter<LiveAdapter.ViewHolder>() {
    private val  mContext = context
    private val liveArray = arrayOf(
        "CCTV中国中央电视台-8 电视剧","东南卫视高清",
        "甘肃卫视","湖北卫视高清","江苏卫视高清",
        "山东卫视高清","深圳卫视高清","天津卫视高清"
    )

    private val liveUrlArray = arrayOf(
        "http://117.169.120.140:8080/live/cctv-8/.m3u8","http://117.169.120.140:8080/live/dongnanstv/.m3u8",
        "http://117.169.120.140:8080/live/gansustv/.m3u8","http://117.169.120.140:8080/live/hdhubeistv/.m3u8",
        "http://117.169.120.140:8080/live/hdjiangsustv/.m3u8","http://117.169.120.140:8080/live/hdshandongstv/.m3u8",
        "http://117.169.120.140:8080/live/hdshenzhenstv/.m3u8","http://117.169.120.140:8080/live/hdtianjinstv/.m3u8"
    )

    inner class ViewHolder(view: View): RecyclerView.ViewHolder(view){
        val liveName: TextView = view.findViewById(R.id.live_name)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LiveAdapter.ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.live_item,parent,false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: LiveAdapter.ViewHolder, position: Int) {
        val liveName = liveArray[position]
        holder.liveName.text = liveName
        holder.liveName.setOnClickListener {
            val intent = Intent(mContext,LiveActivity::class.java)
            intent.putExtra("url",liveUrlArray[position])
            intent.putExtra("title",liveArray[position])
            mContext.startActivity(intent)
        }
    }

    override fun getItemCount(): Int {
        return liveArray.size
    }
}